enum CoordType {
  WGS84 = 'wgs84',
  GCJ02 = 'gcj02',
  BD09 = 'bd09'
}

const x_PI: number = (Math.PI * 3000.0) / 180.0
const a = 6378245.0
const ee = 6.693421622965943e-3 // 科学计数法表示

export function transformBD09ToGCJ02(lng: number, lat: number): number[] {
  const x: number = lng - 0.0065
  const y: number = lat - 0.006
  const z: number = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_PI)
  const theta: number = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_PI)
  const gcj_lng: number = z * Math.cos(theta)
  const gcj_lat: number = z * Math.sin(theta)
  return [gcj_lng, gcj_lat]
}

export function transformGCJ02ToBD09(lng: number, lat: number): number[] {
  const z: number = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI)
  const theta: number = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI)
  const bd_lng: number = z * Math.cos(theta) + 0.0065
  const bd_lat: number = z * Math.sin(theta) + 0.006
  return [bd_lng, bd_lat]
}
